package com.itheima.ydd.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.ydd.common.R;
import com.itheima.ydd.common.ResultData;
import com.itheima.ydd.entity.SysMenu;
import com.itheima.ydd.service.ISysMenuService;
import com.itheima.ydd.utils.JwtUtils;
import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 * 菜单表 前端控制器
 * </p>
 *
 * @author author
 * @since 2022-05-22
 */
@Slf4j
@RestController
@RequestMapping("/sys_menu")
public class SysMenuController {
    @Autowired
    private ISysMenuService sysMenuService;

    @GetMapping("/allData")
    public ResultData allData() {

        return sysMenuService.allData();

    }

    /**
     * 回显
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    public ResultData rowInfo(Integer id){
        SysMenu byId = sysMenuService.getById(id);
        return ResultData.ok("",byId);
    }

    /**
     * 更新
     * @param sysMenu
     * @return
     */
    @PostMapping("/update")
    public ResultData update(@RequestBody SysMenu sysMenu){
        sysMenu.setUpdateDate(LocalDateTime.now());
        sysMenuService.updateById(sysMenu);
        return ResultData.ok("修改成功","");

    }

    /**
     * 添加
     * @param sysMenu
     * @return
     */
    @PostMapping("/add")
    public ResultData add(@RequestBody SysMenu sysMenu){
        sysMenu.setCreateDate(LocalDateTime.now());
        sysMenu.setUpdateDate(LocalDateTime.now());
        sysMenuService.save(sysMenu);
        return ResultData.ok("添加成功","");

    }
    /**
     * 删除
     */
    @GetMapping("/del")
    public ResultData del(Integer id){
        sysMenuService.del(id);

        return ResultData.ok("删除成功","");
    }
}
